#include "util.hpp"
#include "data.hpp"
#include "server.hpp"

void FileTest()
{
    aod::FileUtil("./www").CreateDirectory();
    aod::FileUtil("./www/index.html").SetContent("<html></html>");
    std::string body;
    aod::FileUtil("./www/index.html").GetContent(&body);
    std::cout << "File content: " << body << std::endl;
    std::cout << "File size: " << aod::FileUtil("./www/index.html").Size() << " bytes" << std::endl;
}

void JsonTest()
{
    Json::Value value;
    value["姓名"] = "张三";
    value["年龄"] = 30;
    value["性别"] = "男";
    value["成绩"].append(77.5);
    value["成绩"].append(88.0);
    value["成绩"].append(92.5);

    std::string body;
    aod::JsonUtil::Serialize(value, &body);
    std::cout << "JSON content: " << body << std::endl;
    
    Json::Value stu;
    aod::JsonUtil::UnSerialize(body, &stu);
    std::cout << stu["姓名"].asString() << std::endl;
    std::cout << stu["年龄"].asInt() << std::endl;
    std::cout << stu["性别"].asString() << std::endl;
    std::cout << "成绩: ";
    for (const auto& score : stu["成绩"])
    {
        std::cout << score.asFloat() << " ";
    }
    std::cout << std::endl;
}

void DataTest()
{
    aod::TableVideo tb_video;
    Json::Value video;
    // video["name"] = "变形金刚";
    // video["info"] = "机器人大战";
    // video["video"] = "/video/robet.map";
    // video["image"] = "/image/robet.jpg";

    // tb_video.Insert(video);
    // tb_video.Update(1, video);
    // tb_video.SelectAll(&video);
    // tb_video.SelectOne(2, &video);
    tb_video.Delete(2);
    // tb_video.SelectLike("金刚", &video);
    // std::string body;
    // aod::JsonUtil::Serialize(video, &body);
    // std::cout << body << std::endl;
}
 
void ServerTest()
{
    aod::Server server(9090);
    server.RunModule();
}

int main()
{
    // FileTest();
    // JsonTest();
    // DataTest();
    ServerTest();
    return 0;
}